import type { VbenFormSchema as FormSchema } from '@vben/common-ui'

import { z } from '@vben/common-ui'
import { $t } from '@vben/locales'
import { computed } from 'vue'

export const addEditFormSchema = computed((): FormSchema[] => [
    {
        fieldName: 'oldPassword',
        label: $t('components.EditPassword.children.oldPassword'),
        component: 'InputPassword',
        rules: 'required'
    },
    {
        fieldName: 'newPassword',
        label: $t('components.EditPassword.children.newPassword'),
        component: 'InputPassword',
        rules: 'required'
    },
    {
        fieldName: 'newPassword2',
        label: $t('components.EditPassword.children.confirmPassword'),
        component: 'InputPassword',
        dependencies: {
            rules(values) {
                if (values && values.newPassword2) {
                    return z
                        .string()
                        .min(1, {
                            message: $t('components.EditPassword.children.confirmPassword')
                        })
                        .refine((value) => value === values.newPassword, {
                            message: $t('components.EditPassword.children.passwordFormat')
                        })
                }

                return 'required'
            },
            triggerFields: ['newPassword']
        }
    }
])
